<?php

use yii\db\Migration;
use yii\db\Schema;

class m170815_015252_add_table_invoice extends Migration
{
    public function up()
    {
        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

        // 发票信息
        $this->createTable('invoice', [
            "id" =>         Schema::TYPE_PK,
            "finance_id" => Schema::TYPE_INTEGER. "(11) NULL COMMENT '关联finance_id' ",
            "code" =>    Schema::TYPE_STRING.    "(20) NULL COMMENT '发票号'",
            "name" =>  Schema::TYPE_INTEGER. "(4) NULL COMMENT '服务项目'",
            "company" =>   Schema::TYPE_STRING. "(128) NULL COMMENT '公司名称'",
            "tax" =>   Schema::TYPE_STRING.  "(128) NULL COMMENT '税号'",
            "bank_account" =>  Schema::TYPE_STRING. "(128) NULL COMMENT '银行帐号'",
            "bank_name" =>  Schema::TYPE_STRING. "(128) NULL COMMENT '银行名称'",
            "address" =>  Schema::TYPE_STRING.  "(128) NULL COMMENT '地址'",
            "phone" =>  Schema::TYPE_STRING.  "(128) NULL COMMENT '电话'",
            "remark" => Schema::TYPE_STRING. "(256) NULL COMMENT '备注'",
            "status" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1提交 2审核通过'",
            "user_id" =>      Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" =>   Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>   Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);

        $this->createTable('invoice_order', [
            "id" =>    Schema::TYPE_PK,
            "order_id" =>  Schema::TYPE_INTEGER. "(11) NULL COMMENT '对应订单ID'",
            "order_code" => Schema::TYPE_STRING. "(16) NULL COMMENT '对应订单编号'",
            "price" =>   Schema::TYPE_DECIMAL. "(10,2) DEFAULT NULL COMMENT '价格'",
            "invoice_id" => Schema::TYPE_INTEGER. "(11) NULL COMMENT '关联invoice id' ",
            "finance_id" => Schema::TYPE_INTEGER. "(11) NULL COMMENT '关联finance_id' ",
            "product_id" => Schema::TYPE_INTEGER. "(11)  NULL COMMENT '团期编号' ",
        ], $tableOptions);

        $this->createTable('invoice_company', [
            "id" =>    Schema::TYPE_PK,
            "company" =>  Schema::TYPE_STRING.   "(128) NULL COMMENT '公司名称'",
            "tax" =>   Schema::TYPE_STRING.  "(128) NULL COMMENT '税号'",
            "bank_account" => Schema::TYPE_STRING.  "(128) NULL COMMENT '银行帐号'",
            "bank_name" =>    Schema::TYPE_STRING.  "(128) NULL COMMENT '银行名称'",
            "address" =>  Schema::TYPE_STRING.  "(128) NULL COMMENT '地址'",
            "phone" =>  Schema::TYPE_STRING.  "(128) NULL COMMENT '电话'",
        ], $tableOptions);
    }

    public function down()
    {
        echo "m170815_015252_add_table_invoice cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
